GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#2835)
by
unknown
06:01
created

$.fn.symphonySelectable   C

Complexity

Conditions 13
Paths 13

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
c 0
b 0
f 0
nc 13
nop 1
dl 0
loc 65
rs 5.9671

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like $.fn.symphonySelectable often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/**
2
 * @package assets
3
 */
4
5
(function($) {
6
	'use strict';
7
8
	/**
9
	 * Create selectable elements. Clicking an item will select it
10
	 * by adding the class <code>.selected</code>. Holding down the shift key
11
	 * while clicking multiple items creates a selection range. Holding the meta key
12
	 * (which is <code>cmd</code> on a Mac or <code>ctrl</code> on Windows) allows
13
	 * the selection of multiple items or the modification of an already selected
14
	 * range of items. Doubleclicking outside the selection list will
15
	 * remove the selection.
16
	 *
17
	 * @name $.symphonySelectable
18
	 * @class
19
	 *
20
	 * @param {Object} options An object specifying containing the attributes specified below
21
	 * @param {String} [options.items='tbody tr:has(input)'] Selector to find items that are selectable
22
	 * item. Needed to properly handle item highlighting when used in connection with the orderable plugin
23
	 * @param {String} [options.ignore='a'] Selector to find elements that should not propagate to the handle
24
	 * @param {String} [optinos.mode='single'] Either 'default' (click removes other selections) or 'additive' (click adds to exisiting selection)
25
	 *
26
	 * @example
27
28
			var selectable = $('table').symphonySelectable();
29
			selectable.find('a').mousedown(function(event) {
30
				event.stopPropagation();
31
			});
32
	 */
33
	$.fn.symphonySelectable = function(options) {
34
		var objects = this,
35
			settings = {
36
				items: 'tbody tr:has(input)',
37
				ignore: 'a',
38
				mode: 'single'
39
			};
40
41
		$.extend(settings, options);
42
43
	/*-------------------------------------------------------------------------
44
		Events
45
	-------------------------------------------------------------------------*/
46
47
		// Select
48
		objects.on('click.selectable', settings.items, function select(event) {
49
			var item = $(this),
50
				items = item.siblings().addBack(),
51
				object = $(event.liveFired),
52
				target = $(event.target),
53
				selection, deselection, first, last;
54
55
			// Ignored elements
56
			if(target.is(settings.ignore)) {
57
				return true;
58
			}
59
60
			// Remove text ranges
61
			if(window.getSelection) {
62
				window.getSelection().removeAllRanges();
63
			}
64
65
			// Range selection
66
			if((event.shiftKey) && items.filter('.selected').length > 0 && !object.is('.single')) {
67
68
				// Select upwards
69
				if(item.prevAll().filter('.selected').length > 0) {
70
					first = items.filter('.selected:first').index();
71
					last = item.index() + 1;
72
				}
73
74
				// Select downwards
75
				else {
76
					first = item.index();
77
					last = items.filter('.selected:last').index() + 1;
78
				}
79
80
				// Get selection
81
				selection = items.slice(first, last);
82
83
				// Deselect items outside the selection range
84
				deselection = items.filter('.selected').not(selection).removeClass('selected').trigger('deselect.selectable');
85
				deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false);
86
87
				// Select range
88
				selection.addClass('selected').trigger('select.selectable');
89
				selection.find('input[type="checkbox"]:hidden:first').prop('checked', true);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
90
			}
91
92
			// Single selection
93
			else {
94
95
				// Press meta or ctrl key to adjust current range, otherwise the selection will be removed
96
				if((!event.metaKey && !event.ctrlKey && settings.mode != 'additive' &&  !target.is('input')) || object.is('.single')) {
97
					deselection = items.not(item).filter('.selected').removeClass('selected').trigger('deselect.selectable');
98
					deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false);
99
				}
100
101
				// Toggle selection
102
				if(item.is('.selected')) {
103
					item.removeClass('selected').trigger('deselect.selectable');
104
					item.find('input[type="checkbox"]:hidden:first').prop('checked', false);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
105
				}
106
				else {
107
					item.addClass('selected').trigger('select.selectable');
108
					item.find('input[type="checkbox"]:hidden:first').prop('checked', true);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
109
				}
110
			}
111
112
		});
113
114
		// Remove all selections by doubleclicking the body
115
		$('body').on('dblclick.selectable', function removeAllSelection() {
116
			objects.find(settings.items).removeClass('selected').trigger('deselect.selectable');
117
		});
118
119
	/*-------------------------------------------------------------------------
120
		Initialisation
121
	-------------------------------------------------------------------------*/
122
123
		// Make selectable
124
		objects.addClass('selectable');
125
126
	/*-----------------------------------------------------------------------*/
127
128
		return objects;
129
	};
130
131
})(window.jQuery);
132